package com.wks.reflect;

import wks.service.TestService;
import wks.service.impl.TestServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkReflect {
    public static void main(String[] args) {
        TestService service = new TestServiceImpl();
        TestService proxyInstance = (TestService) Proxy.newProxyInstance(JdkReflect.class.getClassLoader(), service.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("我套你猴子");
                Object invoke = method.invoke(service, args);
                System.out.println("啊里呀噶痛");
                return invoke;
            }
        });
        String s = proxyInstance.doSomeThing();
        proxyInstance.doAnyThing(s);
    }
}
